package org.jeecg.admin.config;

import com.cybermkd.mongo.kit.MongoKit;
import com.cybermkd.mongo.plugin.MongoPlugin;
import com.mongodb.MongoClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author werdor
 * @Date 2021/12/24 2:12 上午
 **/
@Configuration
@Slf4j
public class MongodbConfig {

    @Value("${jeecg.mongodb.host}")
    private String host;
    @Value("${jeecg.mongodb.port}")
    private Integer port;
    @Value("${jeecg.mongodb.db}")
    private String db;

    @Bean
    public MongoClient mongoPlugin() {
        log.info("--------mongo-Plugin加载中--------");
        MongoPlugin mongoPlugin = new MongoPlugin();
        mongoPlugin.add(host, port);
        mongoPlugin.setDatabase(db);
        MongoClient client = mongoPlugin.getMongoClient();
        MongoKit.INSTANCE.init(client, mongoPlugin.getDatabase());
        log.info("--------mongo-Plugin加载结束--------");
        return client;
    }
}
